import request from '@/utils/request'

// 1、获取管理用户分页列表  GET /admin/acl/user/{page}/{limit}
export const reqGetUserList = (page, limit, searchParams) => {
  return request.get(`/admin/acl/user/${page}/${limit}`, { params: searchParams })
  // return request.get(`/admin/acl/user/${page}/${limit}`)
}

// 2、新增/修改管理用户  POST /admin/acl/user/save  PUT /admin/acl/user/update
export const reqAddOrUpdataUser = (user) => {
  if (user.id) {
    // 有id：修改
    return request.put(`/admin/acl/user/update`, user)
  } else {
    // 没id：新增
    return request.post(`/admin/acl/user/save`, user)
  }
}

// 3、删除用户  DELETE /admin/acl/user/remove/{id}
export const reqDelUser = (id) => {
  return request.delete(`/admin/acl/user/remove/${id}`)
}

// 4、批量删除用户  POST /admin/acl/user/batchRemove
export const reqDelUserAll = (ids) => {
  return request.post(`/admin/acl/user/batchRemove`, ids)
}

// 5、根据用户获取角色数据  GET /admin/acl/user/toAssign/{userId}
export const reqGetUserToAssign = (userId) => {
  return request.get(`/admin/acl/user/toAssign/${userId}`)
}

// 6、根据用户分配角色  POST /admin/acl/user/doAssignRole
export const reqDoAssignRoles = (userId, roleId) => {
  return request.post(`/admin/acl/user/doAssignRole`, {
    userId: userId, // 用户id
    roleIdList: roleId // 包含所有角色id的字符串
  }
  )
}
